package com.google.code.kjug.guava.app;

import com.google.code.kjug.guava.app.domain.Car;
import com.google.code.kjug.guava.app.domain.Make;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.*;

import java.util.*;

public class SearchEngine {

    public static final Comparator<Car> YEAR_COMPARATOR = new Comparator<Car>() {
        public int compare(Car car1, Car car2) {
            return Integer.valueOf(car1.getYear() ).compareTo(Integer.valueOf(car2.getYear()));
        }
    };
    public static final Function<Car,String> TO_LISTING = new Function<Car, String>() {
        @Override
        public String apply(Car car) {
            return ""; //you tell me :-)
        }
    };
    public static final Predicate<Car> CLUNKER_PREDICATE = new Predicate<Car>() {
        @Override
        public boolean apply(Car input) {
            return input.getYear() < 1995;
        }
    };

    Database database;

    public Collection<Car> findCars() {
        return Lists.newArrayList();
    }

    public Collection<String> getCarListings() {
        List<Car> cars = Ordering.compound(Lists.newArrayList(YEAR_COMPARATOR)).reverse().sortedCopy(database.getCars());
        return Sets.newLinkedHashSet(Iterables.transform(cars, TO_LISTING));
    }

    public Collection<String> listMakes() {
        return Lists.newArrayList();
    }

    public Collection<String> findJustCars() {
        return Sets.newLinkedHashSet();
    }

    public Collection<String> findMeAClunker() {
        //hints!
        //Iterables.filter
        //Lists.transform
        return Lists.newArrayList();
    }

    public void setDatabase(Database database) {
        this.database = database;
    }

    public Multimap<String, String> classifyListings() {
        //hints!
        //Multimaps.index
        //Multimaps.transformValues
        return null;
    }
}
